const router = require('koa-router')()
const query = require("../db/mysql");

router.post('/verify',async (ctx,next)=>{
    try{
        const user = ctx.request.body.user
        const pwd = ctx.request.body.pwd
        let sql = `SELECT adminPwd FROM admin WHERE adminId = ?`
        let data = await query(sql,[user])
        let adminPwd = data[0].adminPwd
        ctx.status = 200
        if(pwd == adminPwd){
            ctx.status = 200
            let body = {
                status:200,
                data:1,
                msg:'insert success'
            }
            return ctx.body = body.toString()
        }else{
            ctx.status = 404
            return ctx.body = {
                status:404,
                msg:'pwd is incorect'
            }
        }
    }catch{err=>{
        console.log(err)
        return ctx.body = {
            status:500,
            msg:err
        }
    }}
    await next()
})

module.exports = router